package SwingUiChatting;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JList;
import javax.swing.JTextField;
import javax.swing.JButton;
import javax.swing.JTextArea;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

public class ClientSwingUI {

    private JPanel contentPane;

    private JTextField inputArea;

    protected JList userList;

    protected JTextArea recordPane;

    private JFrame frame;

    private String msg;

    private boolean isClicked=false;


    private String systemMessage;

    public String getSystemMessage() {
        return systemMessage;
    }

    public boolean isClicked() {
        return isClicked;
    }


    public void setClicked(boolean isClicked) {
        this.isClicked = isClicked;
    }


    //获取文本框的输入
    public String getInput() {
        return inputArea.getText();
    }


    /**
     * Create the frame.
     */
    public ClientSwingUI() {
        frame=new JFrame("聊天室控制中心");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setBounds(100, 100, 899, 618);
        contentPane = new JPanel();
        contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
        frame.setContentPane(contentPane);
        contentPane.setLayout(null);


        //用户列表
        userList = new JList<String>();
        userList.setBounds(7, 9, 152, 457);
        contentPane.add(userList);


        //发送按钮
        JButton btnSend = new JButton("发送消息");
        btnSend.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent arg0) {
                isClicked=true;
                //将系统的消息展示在面板上
                recordPane.append("系统消息："+inputArea.getText()+"\n");
                inputArea.setText("");

            }
        });
        btnSend.setBounds(745, 498, 100, 50);
        contentPane.add(btnSend);

        //聊天记录面板
        recordPane = new JTextArea();
        recordPane.setBounds(172, 9, 684, 457);
        contentPane.add(recordPane);
        recordPane.append("欢迎各位来到聊天室"+"\n");


        //输入框
        inputArea = new JTextField();
        inputArea.setBounds(2, 498, 600, 50);
        contentPane.add(inputArea);
        inputArea.setColumns(10);
        frame.setVisible(true);

    }


    //面板显示聊天
    public void showMsg(String message) {
        recordPane.append(msg);
    }

}
